package com.koron.css2.serviceManage.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.bean.PubAccessoryTypeBean;
import com.koron.css2.baseConfig.mapper.BaseAccessoryMetadataMapper;
import com.koron.css2.baseConfig.mapper.PubAccessoryTypeMapper;
import com.koron.css2.serviceManage.bean.AccessorySubmitJudgeBean;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

import java.util.List;

public class AccessorySubmitJudge implements ServerInterface{
	
	private Logger log = LogManager.getLogger(AccessorySubmitJudge.class);

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		MessageBean<String> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", String.class);
		try {
			AccessorySubmitJudgeBean bean = JsonUtils.objectToPojo(req.getData(), AccessorySubmitJudgeBean.class);
			BaseAccessoryMetadataMapper mapper = factory.getMapper(BaseAccessoryMetadataMapper.class);
			PubAccessoryTypeMapper typeMaper = factory.getMapper(PubAccessoryTypeMapper.class,"_default");
			List<String> accessoryNos = mapper.checkAccessoryRequired(bean.getReceiptType(), bean.getReceiptId());
			List<PubAccessoryTypeBean> cdList = typeMaper.selectList();
			String accessoryName = "";
			if(accessoryNos!=null && accessoryNos.size()>0) {
				for(String accessoryNo:accessoryNos) {
					for(PubAccessoryTypeBean accessoryType:cdList) {
						if(accessoryNo.equals(accessoryType.getAccessoryNo()))
							accessoryName = accessoryName+accessoryType.getAccessoryName()+",";
					}
				}
				info.setData(accessoryName+"未上传图片");
				return info;
			}
		} catch (Exception e) {
			info.setCode(Constant.MESSAGE_INT_FAIL);
			info.setDescription("查询附件必传失败");
			log.error(e.getMessage(), e);
		}
		return info;
	}

}
